<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="24">
            <a-form-model-item label="适配终端类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="adaptEquipment">
              <j-dict-select-tag  :disabled=formDisabled  type="list" v-model="model.adaptEquipment" dictCode="adapt_equipment" placeholder="请选择适配终端类型" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="APP二维码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="appUrl">
              <j-image-upload :disabled="formDisabled" isMultiple :number="1" v-model="model.appUrl" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="版本号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="version">
              <a-input :disabled=formDisabled v-model="model.version" placeholder="请输入版本号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="应用号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="versionCode">
              <a-input :disabled=formDisabled v-model="model.versionCode" placeholder="请输入应用号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="下载路径" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="downloadUrl">
              <!-- <a-input :disabled=formDisabled v-model="model.downloadUrl" placeholder="请输入下载路径"  ></a-input> -->
              <j-upload :disabled=formDisabled v-model="model.downloadUrl" v-if="model.adaptEquipment=='1'" placeholder="请输入下载路径"  ></j-upload>
              <a-input :disabled=formDisabled v-model="model.downloadUrl" v-else placeholder="请输入下载路径"  ></a-input> 
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="更新类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="updateType">
              <j-dict-select-tag  :disabled=formDisabled  type="list" v-model="model.updateType" dictCode="update_type" placeholder="请选择更新类型"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否审核" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isCheck">
              <j-dict-select-tag  :disabled=formDisabled  type="list" v-model="model.isCheck" dictCode="yes_or_no" placeholder="请选择是否审核"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="更新信息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="versionInfo">
              <!-- <j-editor
                :disabled="formDisabled" 
                v-model="model.versionInfo"
                ref="editor" style="width: 100%;">
              </j-editor> -->
              <a-textarea :disabled="formDisabled" :max-length="500" v-model="model.versionInfo" rows="4" placeholder="请输入更新信息"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-textarea :disabled="formDisabled" :max-length="500" v-model="model.remark" rows="4" placeholder="请输入备注"/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import JEditor from '@/components/jeecg/JEditor.vue';
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'SysAppConfigForm',
    components: {
      JEditor
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/api/erpmng/sys/app/config/sysAppConfig/add",
          edit: "/api/erpmng/sys/app/config/sysAppConfig/edit",
          queryById: "/api/erpmng/sys/app/config/sysAppConfig/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.$refs.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>
